/**
 *  @file: LCD.h
 *  @author: nwz
 *  @brief: 
 *  @date: 2024��8��2��
 * 
 */

#pragma once
#include <basic_header.h>

namespace bsp {

/*
 *
 */
class LCD {
public:
	LCD();
	virtual ~LCD();

	void init();
	void enterSleep();

	void exitSleep();

	enum class Color : uint16_t {
		RED = 0x00F8, BLUE = 0x1F00, GREEN = 0xE007
	};

	void fillScreen(Color color);
	void fillScreen_DMA(Color color);

	void setWindow(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2);
	void sendDMA(int x1, int y1, int x2, int y2,const uint8_t* data, int size);
	void sendDMACallback();

private:
	void hardwareInit();
	void sendDMA(const uint8_t* data, uint32_t size);
	void cspin(uint8_t val);
	void dcpin(uint8_t val);
	void resetPin(uint8_t val);
	void reset();

	void send(uint8_t val);
	void writeREG(uint8_t val);
	void writeData8(uint8_t val);
	void writeData16(uint16_t val);

	SemaphoreHandle_t sem_dma;
};

} /* namespace task */
